﻿using System;
using System.Configuration;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// 发件人元素
    /// </summary>
    public sealed class MailFromElement : ConfigurationElement
    {
        /// <summary>
        /// 发送发地址
        /// </summary>
        [ConfigurationProperty("address", IsRequired = true)]
        public string Address
        {
            get
            {
                return (string)this["address"];
            }
        }

        /// <summary>
        /// 主机地址，如smtp.sohu.com
        /// </summary>
        [ConfigurationProperty("host", IsRequired = true)]
        public string Host
        {
            get
            {
                return (string)this["host"];
            }
        }

        /// <summary>
        /// 发送端口，默认25
        /// </summary>
        [ConfigurationProperty("port", IsRequired = false, DefaultValue = 25)]
        public int Port
        {
            get
            {
                return (int)this["port"];
            }
        }

        /// <summary>
        /// 获取发送方配置对象
        /// </summary>
        /// <returns></returns>
        public MailFrom GetMailFromObject()
        {
            return new MailFrom(this.Address, this.Host, this.Port);
        }
    }
}
